﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Com.Toook.Common;
using System.Data.OleDb;

public partial class nst_joke_JokeAdd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitTypeData();
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string sql = "insert into PublishJoke(title, content, typePageId, score, author) " +
            " values(@title, @content, @typePageId, @score, author)";
        OleDbConnection con = AccessHelper.GetConnection();
        OleDbCommand cmd = new OleDbCommand(sql, con);
        cmd.Parameters.Add("@title", OleDbType.VarWChar, 30).Value = txtTitle.Text;
        cmd.Parameters.Add("@content", OleDbType.LongVarWChar).Value = txtContent.Text;
        cmd.Parameters.Add("@typePageId", DbType.Int32).Value = PageData.GetNextTypePageId(int.Parse(ddlType.SelectedValue));
        cmd.Parameters.Add("@score", OleDbType.Integer).Value = ddlScore.SelectedValue;
        cmd.Parameters.Add("@author", OleDbType.VarWChar, 50).Value = txtAuthor.Text;
        try
        {
            con.Open();            
            cmd.ExecuteNonQuery();
            PageData.UpdateTypeTotalCount(ddlType.SelectedValue);
            PageData.RefreshPageParam();
            lblMsg.Text = "添加成功：" + txtTitle.Text;
            txtTitle.Text = "";
            txtContent.Text = "";            
        }
        catch(Exception ex)
        {
            lblMsg.Text = "添加失败" + ex.Message;
            LogHelper.Log.Error(ex);
        }
        finally
        {
            con.Close();
        }
    }
    private void InitTypeData()//初始化分类 下拉列表
    {
        DataRow[] rows = PageData.SelectParamRows("parentId=50");
        foreach (DataRow row in rows)
        {
            ddlType.Items.Add(new ListItem(row["typeName"].ToString(), row["typeId"].ToString()));
        }
    }
}
